////////////////////////////////////////////////////////////
//
// SFML GUI - Simple and Fast GUI Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) (for SFML)
// Copyright (C) 2010 Janniaux Alexandre (alexand69580@yahoo.fr) (for GUI)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
//    you must not claim that you wrote the original software.
//    If you use this software in a product, an acknowledgment
//    in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
//    and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////

#include "Frame.hpp"

namespace gui
{

Frame::Frame(Widget* parent) :
    Widget(parent)
{
    myBgColor = sf::Color(255,255,255);
    myBorderColor = sf::Color(0,0,0);
    myBorderSize = 1;
}

void Frame::SetBgColor(const sf::Color& bg)
{
    myBgColor = bg;
}

void Frame::SetBorderColor(const sf::Color& border)
{
    myBorderColor = border;
}

void Frame::Render(sf::RenderTarget& target, sf::Renderer &renderer) const
{

    RenderWidget(target,renderer);

    Widget::RenderWidget(target,renderer);
}

void Frame::RenderWidget(sf::RenderTarget& target, sf::Renderer& renderer) const
{
   renderer.SetTexture(NULL);

    renderer.Begin(sf::Renderer::TriangleStrip);
        // border
    renderer.SetColor(myBorderColor);
        renderer.AddVertex(myRect.Left-myBorderSize, myRect.Top-myBorderSize);
        renderer.AddVertex(myRect.Right+myBorderSize, myRect.Top-myBorderSize);
        renderer.AddVertex(myRect.Left-myBorderSize, myRect.Bottom+myBorderSize);
        renderer.AddVertex(myRect.Right+myBorderSize, myRect.Bottom+myBorderSize);

        // frame bg
    renderer.SetColor(myBgColor);
        renderer.AddVertex(myRect.Left, myRect.Top);
        renderer.AddVertex(myRect.Right, myRect.Top);
        renderer.AddVertex(myRect.Left, myRect.Bottom);
        renderer.AddVertex(myRect.Right, myRect.Bottom);
    renderer.End();
}

} // namespace gui
